#include "Handle.h"

void Handle_GPIOInit(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOA,ENABLE);
	RCC_ADCCLKConfig(RCC_PCLK2_Div6);
	
	
 	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
 	GPIO_Init(GPIOB, &GPIO_InitStructure);
	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
 	GPIO_Init(GPIOA, &GPIO_InitStructure);


}

void Handle_ADCInit(void)
{
	ADC_InitTypeDef	ADC_InitTypeDefStruct;
//	ADC_RegularChannelConfig(ADC1,ADC_Channel_8,1,ADC_SampleTime_55Cycles5);
	ADC_InjectedChannelConfig(ADC1,ADC_Channel_9,1,ADC_SampleTime_55Cycles5);
	ADC_InjectedChannelConfig(ADC1,ADC_Channel_4,2,ADC_SampleTime_55Cycles5);
	ADC_InjectedSequencerLengthConfig(ADC1,2);
	
	
	ADC_InitTypeDefStruct.ADC_Mode = ADC_Mode_Independent;
	ADC_InitTypeDefStruct.ADC_ScanConvMode = ENABLE;
	ADC_InitTypeDefStruct.ADC_ContinuousConvMode = ENABLE;
	ADC_InitTypeDefStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
	ADC_InitTypeDefStruct.ADC_DataAlign = ADC_DataAlign_Right;
	ADC_InitTypeDefStruct.ADC_NbrOfChannel = 2;
	ADC_Init(ADC1,&ADC_InitTypeDefStruct);
	
	ADC_ExternalTrigInjectedConvConfig(ADC1,ADC_ExternalTrigInjecConv_None);
	ADC_Cmd(ADC1,ENABLE);
	ADC_AutoInjectedConvCmd(ADC1,ENABLE);
	
	ADC_ResetCalibration(ADC1);
	while(ADC_GetResetCalibrationStatus(ADC1) == SET);
	ADC_StartCalibration(ADC1);
	while(ADC_GetCalibrationStatus(ADC1) == SET);
}

void Handle_ALLInit(void)
{
	Handle_GPIOInit();
	Handle_ADCInit();
}
